<?php

namespace app\admin\controller\company;

use app\common\controller\Backend;
use think\exception\DbException;
use think\response\Json;

/**
 * 公司职位管理
 *
 * @icon fa fa-circle-o
 */
class CompanyPosition extends Backend
{

    /**
     * CompanyPosition模型对象
     * @var \app\admin\model\company\CompanyPosition
     */
    protected $model = null;

    protected $noNeedRight = ['selectpage'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\company\CompanyPosition;
        $this->view->assign("statusList", $this->model->getStatusList());
    }





    /**
     * 查看
     *
     * @return string|Json
     * @throws \think\Exception
     * @throws DbException
     */
    public function index($ids = null)
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        $has_where = [];
        if($ids) {
            $has_where = [
                'company_id' => $ids
            ];
        }
        $this->view->assign('question_id',$ids);
        $this->assignconfig('question_id',$ids);
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model
            ->with(['company','industry','position','worktype'])
            ->where($has_where)
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
        foreach ($list as $row) {
            $region = model('app\admin\model\Region')->whereIn('id',$row->region_ids)->column('name');
            $row->region = implode(',',$region);
        }
        $result = ['total' => $list->total(), 'rows' => $list->items()];
        return json($result);
    }


    public function selectpage()
    {
        return parent::selectpage(); // TODO: Change the autogenerated stub
    }

}
